package cn.tedu._05mvcboot01.controller;

import cn.tedu._05mvcboot01.poji.dto.UserRegDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/*
Controller注解:
1.作用：表示当前类为控制器，用来接收客户端发送的请求;

 */
@Controller
public class UserController {
    /*
    RequestMapping注解:请求注解，根据请求的地址映射到对应的控制器方法
    ResponseBody注解:
       1.允许控制器方法已返回值的形式返回给客户端数据;
    3.客户端传递用户名和密码到服务端

     */
    @RequestMapping("/v1/users/login")
    @ResponseBody
    public String login() {
        return "恭喜您，登录成功";
    }
    //注册功能：http://localhost:8080/v1/users/reg1?username=admin&password=123456
    @RequestMapping("/v1/users/reg1")
    @ResponseBody
    public String reg1(HttpServletRequest request){
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        return username+"......"+password;
    }
    @RequestMapping("/v1/users/reg2")
    @ResponseBody
    public String reg2(String username,String password){
        return username+"***"+password ;
    }
    @RequestMapping("/v1/users/reg3")
    @ResponseBody
    public String reg3(UserRegDTO userRegDTO){
        String username = userRegDTO.getUsername();
        String password = userRegDTO.getPassword();
        return username+"~~"+password;
    }
}
